#include <stdio.h>
#include <octopus.h>

int
main ()
{

  struct octopus_context octopus;

  if (!octopus_init (&octopus))
	 printf ("%s\n", octopus.error_str);

  printf ("init ready\n");

  if (octopus_open (&octopus) < 0)
	 {
		printf ("%s\n", octopus.error_str);
		exit (0);
	 }


  printf ("open ready\n");
  if (octopus_93c46_init (&octopus) < 0)
	 {
		printf ("ERROR: %s\n", octopus.error_str);
	 }

  printf ("flash ready\n");


  unsigned char address = 0x01;

  int length = 128;

  unsigned char buffer[length];
  int i;
  

  for (i = 0; i < length; i++)
	 buffer[i] = i;

  octopus_93c46_write (&octopus, address, length, buffer);

  /* clear buffer */
  for (i = 0; i < length; i++)
	 buffer[i] = 0;


  octopus_93c46_read (&octopus, address, length, buffer);
  int j,c=0;
  for (j = 0; j < 16; j++)
  {
    for (i = 0; i < 8; i++)
	 printf ("%0x ", buffer[c++]);
    printf("\n");
  }
//  char desc[64];
//  octopus_get_hwdesc (&octopus, desc);
//  printf ("Device: %s\n", desc);

  if (octopus_close (&octopus) < 1)
	 printf ("ERROR: %s\n", octopus.error_str);

  return 0;


}
